'use strict'

let http = require('http');
let fs = require('fs');
let path = require('path');

let workSpace = path.resolve('.');



let server = http.createServer((req,res)=>{
    res.write('<head><meta charset="utf8" ></head>');
    let url = req.url;
    console.log(url);
    if(url!=="/favicon.ico"){
        let fullPath=path.join(workSpace,url);
        fs.readdirSync(fullPath).forEach((item)=>{
            if(item==="index.html" || item === "a.html" || item ==="b.html"){
                let fileName = path.join(fullPath,item);
                console.log(fileName);
                // fs.createReadStream(fileName).pipe(res);

                fs.readFile(fileName,(err,data)=>{
                    if(!err){
                        res.end(data);
                    }
                })
            }
        })
    }


})

let port = 3080;
server.listen(port);

console.log(`运行在：http://127.0.0.1:${port}`);
console.log(`运行在：http://127.0.0.1:${port}/home/admin`);
console.log(`运行在：http://127.0.0.1:${port}/wang/pang/qing/tou`);